package Born.utils
{	
	public class ScaleDisplay
	{
		private var _image					:*;
		private var imageAspectRatio		:Number;
		private var stageAspectRatio		:Number;
		private var imageWidth				:Number;
		private var imageHeight				:Number;		
		private var oldWidth				:Number;
		private var oldHeight				:Number;
		
		public function ScaleDisplay()
		{
			/* 	Do nothing, 
				use fill() or showAll() to execute something. */
		}
		/**
		 * Will Fill the window or the defined space <br />
		 * will expand the displayObject when width and height is less than MAX.
		 * @param $image 	: Display Object that will be scaled
		 * @param $width 	: Max width
		 * @param $height 	: Max height
		 */		
		public function fill($image:*,$width:Number,$height:Number):void
		{
			_image 				= $image;			
			oldWidth 			= $image.width;
			oldHeight 			= $image.height;
			imageWidth 			= $width;
			imageHeight 		= $height;
			imageAspectRatio 	= _image.width/_image.height;
			stageAspectRatio 	= imageWidth/imageHeight;
			
			if ( stageAspectRatio >= imageAspectRatio )
			{
				_image.width = imageWidth;
				_image.height = (imageWidth/imageAspectRatio);
			} 
			else
			{
				_image.width = (imageHeight*imageAspectRatio);
				_image.height = imageHeight;
			}
		}
		/**
		 * Will show all on the defined space <br />
		 * will expand the displayObject width and height at the first is equal MAX
		 * @param $image 	: Display Object that will be scaled
		 * @param $width 	: Max width
		 * @param $height 	: Max height
		 */			
		public function showAll($image:*,$width:Number,$height:Number):void
		{
			_image 				= $image;			
			oldWidth 			= $image.width;
			oldHeight 			= $image.height;
			imageWidth 			= $width;
			imageHeight 		= $height;
			imageAspectRatio 	= _image.width/_image.height;
			stageAspectRatio 	= imageWidth/imageHeight;
			
			if ( stageAspectRatio >= imageAspectRatio )
			{
				_image.width = (imageHeight*imageAspectRatio);
				_image.height = imageHeight;
			} 
			else
			{
				_image.width = imageWidth;
				_image.height = (imageWidth/imageAspectRatio);
			}
		}
		/**
		 * Reset the width and height to the original size 
		 */		
		public function resetSize():void
		{
			_image.width = oldWidth;
			_image.height = oldHeight;
		}

	}
}